package com.lanren.astar;

import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) {
        System.out.println("A星寻路算法");
        List<String> path = new ArrayList<>();
        int[][] maps = {
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0},
                {0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0},
                {0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0},
                {0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}
        };
        String[][] imgMaps = {
                {"25,25", "75,25", "125,25", "175,25", "225,25", "275,25", "325,25", "375,25", "425,25", "475,25", "525,25", "575,25", "625,25", "675,25", "725,25"},
                {"25,75", "75,75", "125,75", "175,75", "225,75", "275,75", "325,75", "375,75", "425,75", "475,75", "525,75", "575,75", "625,75", "675,75", "725,75"},
                {"25,125", "75,125", "125,125", "175,125", "225,125", "275,125", "325,125", "375,125", "425,125", "475,125", "525,125", "575,125", "625,125", "675,125", "725,125"},
                {"25,175", "75,175", "125,175", "175,175", "225,175", "275,175", "325,175", "375,175", "425,175", "475,175", "525,175", "575,175", "625,175", "675,175", "725,175"},
                {"25,225", "75,225", "125,225", "175,225", "225,225", "275,225", "325,225", "375,225", "425,225", "475,225", "525,225", "575,225", "625,225", "675,225", "725,225"},
                {"25,275", "75,275", "125,275", "175,275", "225,275", "275,275", "325,275", "375,275", "425,275", "475,275", "525,275", "575,275", "625,275", "675,275", "725,275"},
                {"25,325", "75,325", "125,325", "175,325", "225,325", "275,325", "325,325", "375,325", "425,325", "475,325", "525,325", "575,325", "625,325", "675,325", "725,325"}
        };

        MapInfo info = new MapInfo(maps, path, maps[0].length, maps.length, new Node(1, 5), new Node(10, 4));
        new AStar().start(info);
        printMap(maps, imgMaps, path);
    }

    /**
     * 打印地图
     */
    public static void printMap(int[][] maps, String[][] imgMaps, List<String> path) {
        for (int i = 0; i < maps.length; i++) {
            for (int j = 0; j < maps[i].length; j++) {
                System.out.print(maps[i][j] + " ");
            }
            System.out.println();
        }

        for (int size = path.size(); size > 0; size--) {
            String[] xy =path.get(size-1).split(",");
            System.out.print(imgMaps[Integer.valueOf(xy[0])][Integer.valueOf(xy[1])] + " ");
        }
    }


}
